/* ENM - Enlightenned Network Monitoring Library
 * Copyright (C) 2011 Cedric Bail
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;
 * if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef ENM_H_
# define ENM_H_

#include <Eina.h>

typedef enum _Enm_Message_Protocol
{
  ENM_AUTH_REQUEST,
  ENM_AUTH_CHALLENGE,
  ENM_AUTH_ANSWER,
  ENM_AUTH_STORE,

  ENM_NODE_ADD,
  ENM_NODE_DEL,
  ENM_NODE_VALUE_DEFINE,
  ENM_NODE_VALUE_SET,
  ENM_NODE_NOTIFY,

  ENM_LINK_ADD,
  ENM_LINK_DEL,
  ENM_LINK_VALUE_DEFINE,
  ENM_LINK_VALUE_SET,
  ENM_LINK_NOTIFY,

  ENM_GROUP_ADD,
  ENM_GROUP_DEL,
  ENM_GROUP_ASSOCIATE,

  ENM_GROUP_LIST,
  ENM_NODE_LIST,
  ENM_LINK_LIST,

  ENM_GROUP_WATCH,
  ENM_NODE_WATCH,
  ENM_LINK_WATCH,

  ENM_GROUP_UNWATCH,
  ENM_NODE_UNWATCH,
  ENM_LINK_UNWATCH,

  ENM_LAST
} Enm_Message_Protocol;

typedef struct _Enm_Server Enm_Server;

typedef struct _Enm_Client Enm_Client;

typedef struct _Enm_Error Enm_Error;
typedef struct _Enm_Message Enm_Message;

struct _Enm_Message
{
   Enm_Message_Protocol type;
   unsigned short int version;
   union {
      /* FIXME: define message content */
   } u;
};

struct _Enm_Error
{
   const char *message;
};

typedef void (*Enm_Callback_Client)(const Enm_Client *client, const void *msg_data, void *data);
typedef void (*Enm_Callback_Server)(const Enm_Server *server, const void *msg_data, void *data);

typedef enum _Enm_Event
{
  ENM_CLIENT_ADD,     /* msg_data = Enm_Server */
  ENM_CLIENT_DEL,     /* msg_data = Enm_Server */
  ENM_CLIENT_MESSAGE, /* msg_data = Enm_Message */
  ENM_CLIENT_ERROR,   /* msg_data = Enm_Error */

  ENM_SERVER_ADD,     /* msg_data = NULL */
  ENM_SERVER_DEL,     /* msg_data = NULL */
  ENM_SERVER_MESSAGE, /* msg_data = Enm_Message */
  ENM_SERVER_ERROR    /* msg_data = Enm_Error */
} Enm_Event;

EAPI Eina_Bool enm_init(void);
EAPI Eina_Bool enm_shutdown(void);

EAPI Enm_Server *enm_server_add(const char *name, int port, const void *data);
EAPI Enm_Server *enm_server_connect(const char *name, int port, const void *data);

EAPI void enm_server_del(Enm_Server *server);
EAPI void enm_client_del(Enm_Client *client);

EAPI Eina_Bool enm_server_send(Enm_Server *server, Enm_Message *message);
EAPI Eina_Bool enm_client_send(Enm_Client *client, Enm_Message *message);

EAPI Enm_Server *enm_client_server_get(Enm_Client *client);

EAPI Eina_Bool enm_callback_client_add(Enm_Client *client, Enm_Event event, Enm_Callback_Client *cb, const void *data);
EAPI Eina_Bool enm_callback_client_del(Enm_Client *client, Enm_Event event, Enm_Callback_Client *cb, const void *data);

EAPI Eina_Bool enm_callback_server_add(Enm_Server *server, Enm_Event event, Enm_Callback_Server *cb, const void *data);
EAPI Eina_Bool enm_callback_server_del(Enm_Server *server, Enm_Event event, Enm_Callback_Server *cb, const void *data);

#endif
